import React, { useState, useEffect } from 'react'
import Getnew from './components/Getnew/Getnew'
import Goodslist from './components/Goodslist/Goodslist'
import { reqgetnew, reqgetindexgoods } from '../../http/api'

export default function Home() {
  const [newshop, setnewshop] = useState([])
  const [goodlist, setgoodlist] = useState([])
  const [n, setn] = useState(1)
  useEffect(() => {
    reqgetnew().then((res) => {
      if (res.data.code === 200) {
        setnewshop(
          res.data.list
        )
      }
    })
    reqgetindexgoods().then((res) => {
      if (res.data.code === 200) {
        setgoodlist(
          res.data.list
        )
      }
    })
  }, [])

  const changeIndex = (n) => {
    setn(n)
  }
  return (
    <div>
      <Getnew newshop={newshop}></Getnew>
      <Goodslist goodlist={goodlist} changeIndex={(n) => changeIndex(n)} n={n}></Goodslist>
    </div>
  )
}
